package org.flint92.springboot.servlet.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;

/**
 * @author flint92
 */
@WebServlet(
        name = "myServlet",
        urlPatterns = {"/my-servlet"},
        initParams = {
                @WebInitParam(name = "param", value = "paramValue")
        }
)
public class MyServlet extends HttpServlet {
    private static final long serialVersionUID = -5056120946506238411L;

    private String value;

    @Override
    public void init(ServletConfig config) throws ServletException {
        this.value = config.getInitParameter("param");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        Writer writer = resp.getWriter();

        writer.write("<html><body>Hello, " + this.value + "</body></html>");

        writer.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
